<?php
foreach($posts as $post) {
  ?>
    <div class="post-list col-md-12">
      <div class="row">
        <div class="col-md-2">
          <a href="<?php echo base_url('post/view/'.$post['url']); ?>" class="thumbnail" target="_blank">
            <?php if(!empty($post["images"])){
                  foreach( $post["images"]  as $img) :
                    if($img['firstimage'] == 1){
                ?>
                      <img src="<?php echo base_url($img["small"]);?>" alt="<?php echo $post['title']; ?>">
                <?php
                    }
                 endforeach;
                }else{
                ?>
                  <img src="<?php echo $imagepath."/not_available.jpg";?>" alt="<?php echo $post['title']; ?>">
                <?php
                }
                ?>

          </a>
        </div>
        <div class="col-md-8">
          <h2><a href="<?php echo base_url('post/view/'.$post['url']); ?>"><?php echo $post["title"]; ?></a></h2>
          
          <p class="post-detail">
            <?php echo mb_substr((strip_tags($post['content'])), 0, 150); ?> <a href="#">ดูรายละเอียด</a>
          </p>
          <small class="text-muted">
            <div class="mic-info">
              โดย: <a href="<?php echo base_url("post/user/".$post['user']['username']);?>"><?php echo $post['user']["first_name"]." ".$post['user']["last_name"]; ?></a> เมื่อ <?php echo Util::ezDate($post['cr_date']); ?> 
            </div>
          </small>
          <?php 
            $urlCat = array();
            foreach ($post["categories"] as $catKey => $catValue) {
              $urlCat[] = $catValue["url"];
              echo "<a href=\"".base_url("category/".implode("/", $urlCat))."\"  target=\"_blank\"><span class=\"label label-info\">".$catValue["name"]."</span></a>";
              if($catKey < (count($post["categories"])-1)){
                echo " &raquo; ";
              }
            }
          ?>
        </div>
        <div class="col-md-2">
          <div class="col-xs-12 post-price-type">
            <?php echo $post["type"]["name"];?>
          </div>
          <div class="col-xs-12 post-price-number">
            <?php echo number_format(preg_replace("/[^0-9]/","", $post["meta"]["price"]), 0, '.', ','); ?>
          </div> 
          <div class="col-xs-12 post-price-province">
            <?php echo (!empty($post["meta"]["province"]) ? Util::getProvince($post["meta"]["province"]) : "");?>
          </div> 
        </div>
      </div>
    </div>
  <?php
}
?>